package com.ohxwj.modules.sys.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ohxwj.modules.sys.dao.SysRoleXcxDao;
import com.ohxwj.modules.sys.entity.SysRoleXcxEntity;
import com.ohxwj.modules.sys.service.SysRoleXcxService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 角色小程序功能关联
 *
 * @author xuwenjie
 * @date 2018-01-13 22:41:18
 */

@Service("sysRoleXcxService")
public class SysRoleXcxServiceImpl implements SysRoleXcxService {
	@Autowired
	private SysRoleXcxDao sysRoleXcxDao;
	
	@Override
	public SysRoleXcxEntity queryObject(Long id){
		return sysRoleXcxDao.queryObject(id);
	}
	
	@Override
	public List<SysRoleXcxEntity> queryList(Map<String, Object> map){
		return sysRoleXcxDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return sysRoleXcxDao.queryTotal(map);
	}
	
	@Override
	public void save(SysRoleXcxEntity sysRoleXcx){
		sysRoleXcxDao.save(sysRoleXcx);
	}
	
	@Override
	public void update(SysRoleXcxEntity sysRoleXcx){
		sysRoleXcxDao.update(sysRoleXcx);
	}
	
	@Override
	public void delete(Long id){
		sysRoleXcxDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		sysRoleXcxDao.deleteBatch(ids);
	}


	@Override
	@Transactional
	public void saveOrUpdate(Long roleId, List<Long> xcxIdList) {
		//先删除角色与菜单关系
		sysRoleXcxDao.delete(roleId);

		if(xcxIdList.size() == 0){
			return ;
		}

		//保存角色与菜单关系
		Map<String, Object> map = new HashMap<>();
		map.put("roleId", roleId);
		map.put("xcxIdList", xcxIdList);
		sysRoleXcxDao.save(map);
	}

	@Override
	public List<Long> queryXcxIdList(Long roleId) {
		return sysRoleXcxDao.queryXcxIdList(roleId);
	}
	
}
